//
//  LXConverstaionViewController.m
//  ZuLinProject
//
//  Created by bancheng on 2022/6/30.
//  Copyright © 2022 LX_App. All rights reserved.
//

#import "LXConverstaionViewController.h"
#import "LXMessageRepairCarInfo.h"
#import "LXMessageRepairCarCell.h"
#import "LXCarLeaseApplyViewController.h"
@interface LXConverstaionViewController ()

@end

@implementation LXConverstaionViewController

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    // 禁用侧滑返回
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNav];
    
    [self registerClass:[LXMessageRepairCarCell class] forMessageClass:[LXMessageRepairCarInfo class]];
    
    
    
    [self.chatSessionInputBarControl.pluginBoardView.allItems removeAllObjects];
    UIView *v = [[UIView alloc] initWithFrame:self.chatSessionInputBarControl.pluginBoardView.bounds];
    [self.chatSessionInputBarControl.pluginBoardView addSubview:v];
    
    
    NSArray *arr = @[
        @{
            @"image":@"rong_picture",
            @"tag":@(1001),
            @"title":@"图片/视频",
        },
        @{
            @"image":@"rong_takePhoto",
            @"tag":@(1002),
            @"title":@"拍摄",
        },
        @{
            @"image":@"rong_location",
            @"tag":@(1003),
            @"title":@"坐标",
        }
    ];
    CGFloat X = 0;
    for (NSDictionary *dic in arr) {
        
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(X, 0, ScreenWidth/3, v.height)];
        [btn setTitle:dic[@"title"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:dic[@"image"]] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        [btn setTitleColor:[UIColor colorWithHexString:@"#191F25"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(clickPluaginBoardAction:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = [dic[@"tag"] integerValue];
        [btn setIconInTopWithSpacing:10];
        X += btn.width;
        [v addSubview:btn];
    }
    
    
    
//    LXMessageRepairCarInfo *model = [LXMessageRepairCarInfo new];
//    [[RCIM sharedRCIM] sendMessage:self.conversationType
//                          targetId:self.targetId
//                           content:model
//                       pushContent:nil
//                          pushData:nil
//                           success:^(long messageId) {
//        NSLog(@"");
//    }
//                             error:^(RCErrorCode nErrorCode, long messageId) {
//        NSLog(@"");
//    }];
    
    
}

- (void)didTapMessageCell:(RCMessageModel *)model{
    [super didTapMessageCell:model];
    if ([model.objectName isEqualToString:@"LX:WeNeedCar:Info"]) {
        
        LXMessageRepairCarInfo *content = (LXMessageRepairCarInfo *)model.content;
        
        AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
        app.model = model;
        
        LXCarLeaseApplyViewController *vc = [[LXCarLeaseApplyViewController alloc] init];
        NSDictionary *dic = @{
            @"id":content.carModelId,
            @"carBrand":content.carBrand,
            @"carMode":content.carModel,
            @"runPlatfom":content.plaValue,
            @"carType":content.typeValue,
            @"energeType":content.engValue,
            @"floorPrice":content.rentPrice,
            @"endurance":content.endurance,
            @"publishedId":content.carTypeId,
        };
        
        CheLiangModel *mm = [CheLiangModel mj_objectWithKeyValues:dic];
        vc.carModel = mm;
        vc.type = 3;
        vc.fromVc = NSStringFromClass([self class]);
        [self.navigationController pushViewController:vc animated:YES];
        
        
        
    }
}

-(void)setNav{
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
    UIButton *backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    backBtn.frame = CGRectMake(18, KStatuesBarHeight, 40, 40);
    [backBtn setImage:[UIImage imageNamed:@"back_icon"] forState:(UIControlStateNormal)];
    [backBtn addTarget:self action:@selector(pop) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:backBtn];
    
    UILabel *titleLB = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2 - 100, backBtn.Y, 200, 40)];
    titleLB.text = self.textStr;
    titleLB.textColor = UIColor.blackColor;
    titleLB.textAlignment = NSTextAlignmentCenter;
    titleLB.font = [UIFont boldSystemFontOfSize:18];
    [self.view addSubview:titleLB];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

-(void)pop{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark ----- 点击面板
-(void)clickPluaginBoardAction:(UIButton *)sender{
    switch (sender.tag) {
        case 1001:
            [self.chatSessionInputBarControl openSystemAlbum];
            break;
        case 1002:
            [self.chatSessionInputBarControl openSystemCamera];
            break;
        case 1003:
            [self.chatSessionInputBarControl openLocationPicker];
            break;
        default:
            break;
    }
}
@end
